"use strict";
const electron = require("electron");
electron.contextBridge.exposeInMainWorld("electronAPI", {
  /**
   * A generic task runner for all main process functions.
   * This is the single entry point for all main process interactions.
   * @param taskName - The name of the task to run, corresponding to a case in main.ts's 'run-task' handler.
   * @param args - Arguments for the task.
   * @returns A promise that resolves with the result of the task.
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  runTask: (taskName, ...args) => electron.ipcRenderer.invoke("run-task", taskName, ...args),
  /**
   * Securely expose a listener for messages from the main process.
   * @param callback - The function to execute when a message is received.
   *                   It receives the event and message arguments.
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  onMainProcessMessage: (callback) => {
    electron.ipcRenderer.on("main-process-message", callback);
  }
});
